import 'package:flutter/material.dart';

class HomeNav extends StatelessWidget {
  HomeNav({super.key});

  // 导航数据
  List navList = [
    {
      'title': '我的房屋',
      'icon': 'assets/images/house_nav_icon@2x.png',
    },
    {
      'title': '我的报修',
      'icon': 'assets/images/repair_nav_icon@2x.png',
    },
    {
      'title': '访客登记',
      'icon': 'assets/images/visitor_nav_icon@2x.png',
    }
  ];

  List<Widget> getChildren(BuildContext context) {
    return navList.map((item) {
      return Expanded(
        child: GestureDetector(
            onTap: () {
              // --- 导航逻辑 ---
              if (item["title"] == '我的房屋') {
                // 检查标题是否为“我的房屋”
                Navigator.pushNamed(context, '/house'); // 跳转到 /house 路由
              }
            },
            child: Column(
              children: [
                Image.asset(
                  item['icon'],
                  width: 35,
                ),
                Text(item['title']),
              ],
            )),
      );
    }).toList();
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: const EdgeInsets.only(top: 10, bottom: 10),
      padding: const EdgeInsets.only(bottom: 10, top: 10),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(10),
      ),
      child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: getChildren(context)),
    );
  }
}
